<?php
/**
 * 内容管理
 */

class Model_News {
	
	/**
	 * 添加内容
	 *
	 * @param $data array       	
	 */
	public function add_News($data) {
		if (! is_array ( $data )) {
			return false;
		}
		
		$DB_News = new DB_News ();
		return $DB_News->insert ( $data );
	}
	
	/**
	 * 取新闻信息
	 *
	 * @param $id int       	
	 */
	public function Get_News($id) {
		if (empty ( $id ) || ! is_numeric ( $id )) {
			return false;
		}
		
		$DB_News = new DB_News ();
		$News_Info = $DB_News->loadInfoByPrimary ( $id );
		$News_Info ['createtime'] = date ( "Y-m-d H:i:s", $News_Info ['createtime'] );
		$News_Info ['updatetime'] = date ( "Y-m-d H:i:s", $News_Info ['updatetime'] );
		
		$DB_News_Data = new DB_NewsData ( $id );
		$New_Data = $DB_News_Data->loadInfoByPrimary ( $id );
		
		return array_merge ( $News_Info, $New_Data );
	}
	
	/**
	 * 编辑内容
	 *
	 * @param $id int       	
	 * @param $data array       	
	 */
	public function edit_News($id, $data) {
		if (! is_array ( $data ) || empty ( $id )) {
			return false;
		}
		
		$DB_News = new DB_News ();
		if ($DB_News->updateByConditions ( $data, "id={$id}" )) {
			return true;
		}
		return false;
	}
	
	/**
	 * 删除内容
	 *
	 * @param $id int       	
	 */
	public function delete_News($id) {
		if (empty ( $id )) {
			return false;
		}
		$DB_News = new DB_News ();
		$DB_News->delete ( "id={$id}" );
		return true;
	}
}
?>